package dto

import (
	"go-gateway-learn/public"

	"github.com/gin-gonic/gin"
)

type ServiceListInput struct {
	Info     string `json:"info" form:"info" comment:"关键词" example:"0" validate:""`                     //关键词
	PageNo   int    `json:"page_no" form:"page_no" comment:"页数" example:"1" validate:"required"`        //页数
	PageSize int    `json:"page_size" form:"page_size" comment:"每页行数" example:"20" validate:"required"` //每页行数
}

type ServiceListOutput struct {
	Total int64                   `json:"total" form:"total" comment:"总页数" example:"0" validate:""` //总页数
	List  []ServiceListItemOutput `json:"list" form:"list" comment:"列表" validate:""`                //总数
}

type ServiceListItemOutput struct {
	ID          int64  `json:"id" form:"id" comment:"序号" example:"1" validate:""`                               //序号
	ServiceName string `json:"service_name" form:"service_name" comment:"服务名称" example:"TCP" validate:""`       //服务名称
	ServiceDesc string `json:"service_desc" form:"service_desc" comment:"服务说明" example:"详细信息" validate:""`      //服务说明
	LoadType    int    `json:"load_type" form:"load_type" comment:"类型" example:"1" validate:""`                 //类型
	ServiceAddr string `json:"service_addr" form:"service_addr" comment:"服务地址" example:"127.0.0.1" validate:""` //服务地址
	Qps         int64  `json:"qps" form:"qps" comment:"qps" example:"111250" validate:""`                       //每秒查询率
	Qpd         int64  `json:"qpd" form:"qpd" comment:"qpd" example:"111" validate:""`                          //日请求数
	TotalNodes  int    `json:"totle_nodes" form:"totle_nodes" comment:"节点数" example:"126" validate:""`          //节点数
}

type ServiceDelInput struct {
	ID int64 `json:"id" form:"id" comment:"服务ID" example:"1" validate:"required"` //序号
}

type ServiceAddHTTPInput struct {
	ServiceName            string `json:"service_name" form:"service_name" comment:"服务名称" example:"" validate:"required,valid_servicename"`                                     //服务名称
	ServiceDesc            string `json:"service_desc" form:"service_desc" comment:"服务说明" example:"详细信息" validate:"required"`                                     //服务说明
	RuleType               int    `json:"rule_type" form:"rule_type" comment:"接入类型名称" example:"0" validate:"max=1,min=0"`                                                       //接入类型名称
	Rule                   string `json:"rule" form:"rule" comment:"接入路径：域名或前缀" example:"" validate:"required,valid_rule"`                                                      //接入路径：域名或前缀
	NeedHTTPS              int    `json:"need_https" form:"need_https" comment:"是否支持HTTPS 1-支持" example:"1" validate:"max=1,min=0"`                                             //是否支持HTTPS
	NeedStripUri           int    `json:"need_strip_uri" form:"need_strip_uri" comment:"是否启用strip_uri 1-启用" example:"1" validate:"max=1,min=0"`                                 //是否启用strip_uri
	NeedWebsocket          int    `json:"need_websocket" form:"need_websocket" comment:"是否支持websocket 1-支持" example:"1" validate:"max=1,min=0"`                                 //是否支持websocket
	UrlRewrite             string `json:"url_rewrite" form:"url_rewrite" comment:"url重写功能 格式：/gatekeeper/test_service(.*) 多条换行" example:"" validate:"valid_urlrewrite"`       //url重写功能
	HeaderTransfor         string `json:"header_transfor" form:"header_transfor" comment:"headerTransfor支持增加、删除、修改。多个逗号间隔" example:"" validate:"valid_headertransfor"`                //header转换支持增加、删除、修改。多个逗号间隔
	OpenAuth               int    `json:"open_auth" form:"open_auth" comment:"是否开启权限 1-开启" example:"1" validate:"max=1,min=0"`                                                  //是否开启权限
	BlackList              string `json:"black_list" form:"black_list" comment:"黑名单" example:"" validate:""`                                                                    //黑名单
	WhiteList              string `json:"white_list" form:"white_list" comment:"白名单" example:"" validate:""`                                                                    //白名单
	WhiteHostList          string `json:"white_host_list" form:"white_host_list" comment:"白名单主机" example:"" validate:""`                                                        //白名单主机
	ClientIPFlowLimit      int    `json:"clientip_flow_limit" form:"clientip_flow_limit" comment:"客户端是否限流 0-否" example:"0" validate:"max=1,min=0"`                            //客户端是否限流
	ServiceFlowLimit       int    `json:"service_flow_limit" form:"service_flow_limit" comment:"服务端是否限流 0-否" example:"0" validate:"max=1,min=0"`                                //服务端是否限流
	RoundType              int    `json:"round_type" form:"round_type" comment:"轮询方式 0-random,1-round-robin,2-weight_round_robin,3-ip_hash" example:"0" validate:"max=3,min=0"` //轮询方式
	IPList                 string `json:"ip_list" form:"ip_list" comment:"ip列表" example:"" validate:"required,valid_iplist"`                                                    //ip列表
	WeightList             string `json:"weight_list" form:"weight_list" comment:"权重列表" example:"" validate:"required,valid_weightlist"`                                        //权重列表
	// ForbidList             string `json:"forbid_list" form:"forbid_list" comment:"禁用IP列表" example:"" validate:"required"`                                                       //禁用IP列表
	UpstreamConnectTimeout int    `json:"upstream_connect_timeout" form:"upstream_connect_timeout" comment:"建立连接超时" example:"0" validate:"min=0"`                               //建立连接超时
	UpstreamHeaderTimeout  int    `json:"upstream_header_timeout" form:"upstream_header_timeout" comment:"获取header超时" example:"0" validate:"min=0"`                             //获取header超时
	UpstreamIdleTimeout    int    `json:"upstream_idle_timeout" form:"upstream_idle_timeout" comment:"链接最大空闲时间" example:"0" validate:"min=0"`                                   //链接最大空闲时间
	UpstreamMaxIdle        int    `json:"upstream_max_idle" form:"upstream_max_idle" comment:"最大空闲链接数" example:"0" validate:"min=0"`                                            //最大空闲链接数
}

type ServiceUpdateHTTPInput struct {
	ID                     int64  `json:"id" form:"id" comment:"服务ID" example:"1" validate:"required"`                                                                          //序号
	ServiceName            string `json:"service_name" form:"service_name" comment:"服务名称" example:"http_service_indb" validate:"required"`                    //服务名称
	ServiceDesc            string `json:"service_desc" form:"service_desc" comment:"服务说明" example:"http_service_indb" validate:"required"`                        //服务说明
	RuleType               int    `json:"rule_type" form:"rule_type" comment:"接入类型名称" example:"0" validate:"max=1,min=0"`                                                       //接入类型名称
	Rule                   string `json:"rule" form:"rule" comment:"接入路径：域名或前缀" example:"/http_service_indb" validate:"required,valid_rule"`                                    //接入路径：域名或前缀
	NeedHTTPS              int    `json:"need_https" form:"need_https" comment:"是否支持HTTPS 1-支持" example:"1" validate:"max=1,min=0"`                                             //是否支持HTTPS
	NeedStripUri           int    `json:"need_strip_uri" form:"need_strip_uri" comment:"是否启用strip_uri 1-启用" example:"1" validate:"max=1,min=0"`                                 //是否启用strip_uri
	NeedWebsocket          int    `json:"need_websocket" form:"need_websocket" comment:"是否支持websocket 1-支持" example:"1" validate:"max=1,min=0"`                                 //是否支持websocket
	UrlRewrite             string `json:"url_rewrite" form:"url_rewrite" comment:"url重写功能 格式：/gatekeeper/test_service(.*) 多个逗号间隔" example:"" validate:"valid_urlrewrite"`       //url重写功能
	HeaderTransfor         string `json:"header_transfor" form:"header_transfor" comment:"header转换支持增加、删除、修改。多个逗号间隔" example:"" validate:"valid_headertransfor"`                //header转换支持增加、删除、修改。多个逗号间隔
	OpenAuth               int    `json:"open_auth" form:"open_auth" comment:"是否开启权限 1-开启" example:"1" validate:"max=1,min=0"`                                                  //是否开启权限
	BlackList              string `json:"black_list" form:"black_list" comment:"黑名单" example:"" validate:""`                                                                    //黑名单
	WhiteList              string `json:"white_list" form:"white_list" comment:"白名单" example:"" validate:""`                                                                    //白名单
	WhiteHostList          string `json:"white_host_list" form:"white_host_list" comment:"白名单主机" example:"" validate:""`                                                        //白名单主机
	ClientIPFlowLimit      int    `json:"clientip_flow_limit" form:"clientip_flow_limit" comment:"客户端是否限流 0-否" example:"0" validate:"max=1,min=0"`                            //客户端是否限流
	ServiceFlowLimit       int    `json:"service_flow_limit" form:"service_flow_limit" comment:"服务端是否限流 0-否" example:"0" validate:"max=1,min=0"`                                //服务端是否限流
	RoundType              int    `json:"round_type" form:"round_type" comment:"轮询方式 0-random,1-round-robin,2-weight_round_robin,3-ip_hash" example:"0" validate:"max=3,min=0"` //轮询方式
	IPList                 string `json:"ip_list" form:"ip_list" comment:"ip列表" example:"" validate:"required,valid_iplist"`                                                    //ip列表
	WeightList             string `json:"weight_list" form:"weight_list" comment:"权重列表" example:"" validate:"required,valid_weightlist"`                                        //权重列表
	// ForbidList             string `json:"forbid_list" form:"forbid_list" comment:"禁用IP列表" example:"" validate:"required"`                                                       //禁用IP列表
	UpstreamConnectTimeout int    `json:"upstream_connect_timeout" form:"upstream_connect_timeout" comment:"建立连接超时" example:"0" validate:"min=0"`                               //建立连接超时
	UpstreamHeaderTimeout  int    `json:"upstream_header_timeout" form:"upstream_header_timeout" comment:"获取header超时" example:"0" validate:"min=0"`                             //获取header超时
	UpstreamIdleTimeout    int    `json:"upstream_idle_timeout" form:"upstream_idle_timeout" comment:"链接最大空闲时间" example:"0" validate:"min=0"`                                   //链接最大空闲时间
	UpstreamMaxIdle        int    `json:"upstream_max_idle" form:"upstream_max_idle" comment:"最大空闲链接数" example:"0" validate:"min=0"`                                            //最大空闲链接数
}

type ServiceStatOutput struct {
	Today     []int64 `json:"today" form:"today" comment:"当日流量" validate:""`
	Yesterday []int64 `json:"yesterday" form:"yesterday" comment:"昨日流量"  validate:""`
}

type ServiceUpdateTCPInput struct {
	ID                int64  `json:"id" form:"id" comment:"服务ID" validate:"required"`
	ServiceName       string `json:"service_name" form:"service_name" comment:"服务名称" validate:"required,valid_service_name"`
	ServiceDesc       string `json:"service_desc" form:"service_desc" comment:"服务描述" validate:"required"`
	Port              int    `json:"port" form:"port" comment:"端口，需要设置8001-8999范围内" validate:"required,min=8001,max=8999"`
	OpenAuth          int    `json:"open_auth" form:"open_auth" comment:"是否开启权限验证" validate:""`
	BlackList         string `json:"black_list" form:"black_list" comment:"黑名单IP，以逗号间隔，白名单优先级高于黑名单" validate:"valid_iplist"`
	WhiteList         string `json:"white_list" form:"white_list" comment:"白名单IP，以逗号间隔，白名单优先级高于黑名单" validate:"valid_iplist"`
	WhiteHostName     string `json:"white_host_name" form:"white_host_name" comment:"白名单主机，以逗号间隔" validate:"valid_iplist"`
	ClientIPFlowLimit int    `json:"clientip_flow_limit" form:"clientip_flow_limit" comment:"客户端IP限流" validate:""`
	ServiceFlowLimit  int    `json:"service_flow_limit" form:"service_flow_limit" comment:"服务端限流" validate:""`
	RoundType         int    `json:"round_type" form:"round_type" comment:"轮询策略" validate:""`
	IPList            string `json:"ip_list" form:"ip_list" comment:"IP列表" validate:"required,valid_ipportlist"`
	WeightList        string `json:"weight_list" form:"weight_list" comment:"权重列表" validate:"required,valid_weightlist"`
	ForbidList        string `json:"forbid_list" form:"forbid_list" comment:"禁用IP列表" validate:"valid_iplist"`
}

type ServiceAddTCPInput struct {
	ServiceName       string `json:"service_name" form:"service_name" comment:"服务名称" validate:"required,valid_service_name"`
	ServiceDesc       string `json:"service_desc" form:"service_desc" comment:"服务描述" validate:"required"`
	Port              int    `json:"port" form:"port" comment:"端口，需要设置8001-8999范围内" validate:"required,min=8001,max=8999"`
	HeaderTransfor    string `json:"header_transfor" form:"header_transfor" comment:"header头转换" validate:""`
	OpenAuth          int    `json:"open_auth" form:"open_auth" comment:"是否开启权限验证" validate:""`
	BlackList         string `json:"black_list" form:"black_list" comment:"黑名单IP，以逗号间隔，白名单优先级高于黑名单" validate:"valid_iplist"`
	WhiteList         string `json:"white_list" form:"white_list" comment:"白名单IP，以逗号间隔，白名单优先级高于黑名单" validate:"valid_iplist"`
	WhiteHostName     string `json:"white_host_name" form:"white_host_name" comment:"白名单主机，以逗号间隔" validate:"valid_iplist"`
	ClientIPFlowLimit int    `json:"clientip_flow_limit" form:"clientip_flow_limit" comment:"客户端IP限流" validate:""`
	ServiceFlowLimit  int    `json:"service_flow_limit" form:"service_flow_limit" comment:"服务端限流" validate:""`
	RoundType         int    `json:"round_type" form:"round_type" comment:"轮询策略" validate:""`
	IPList            string `json:"ip_list" form:"ip_list" comment:"IP列表" validate:"required,valid_ipportlist"`
	WeightList        string `json:"weight_list" form:"weight_list" comment:"权重列表" validate:"required,valid_weightlist"`
	ForbidList        string `json:"forbid_list" form:"forbid_list" comment:"禁用IP列表" validate:"valid_iplist"`
}

type ServiceUpdateGrpcInput struct {
	ID                int64  `json:"id" form:"id" comment:"服务ID" validate:"required"`
	ServiceName       string `json:"service_name" form:"service_name" comment:"服务名称" validate:"required,valid_service_name"`
	ServiceDesc       string `json:"service_desc" form:"service_desc" comment:"服务描述" validate:"required"`
	Port              int    `json:"port" form:"port" comment:"端口，需要设置8001-8999范围内" validate:"required,min=8001,max=8999"`
	HeaderTransfor    string `json:"header_transfor" form:"header_transfor" comment:"metadata转换" validate:"valid_header_transfor"`
	OpenAuth          int    `json:"open_auth" form:"open_auth" comment:"是否开启权限验证" validate:""`
	BlackList         string `json:"black_list" form:"black_list" comment:"黑名单IP，以逗号间隔，白名单优先级高于黑名单" validate:"valid_iplist"`
	WhiteList         string `json:"white_list" form:"white_list" comment:"白名单IP，以逗号间隔，白名单优先级高于黑名单" validate:"valid_iplist"`
	WhiteHostName     string `json:"white_host_name" form:"white_host_name" comment:"白名单主机，以逗号间隔" validate:"valid_iplist"`
	ClientIPFlowLimit int    `json:"clientip_flow_limit" form:"clientip_flow_limit" comment:"客户端IP限流" validate:""`
	ServiceFlowLimit  int    `json:"service_flow_limit" form:"service_flow_limit" comment:"服务端限流" validate:""`
	RoundType         int    `json:"round_type" form:"round_type" comment:"轮询策略" validate:""`
	IPList            string `json:"ip_list" form:"ip_list" comment:"IP列表" validate:"required,valid_ipportlist"`
	WeightList        string `json:"weight_list" form:"weight_list" comment:"权重列表" validate:"required,valid_weightlist"`
	ForbidList        string `json:"forbid_list" form:"forbid_list" comment:"禁用IP列表" validate:"valid_iplist"`
}

type ServiceAddGrpcInput struct {
	ServiceName       string `json:"service_name" form:"service_name" comment:"服务名称" validate:"required,valid_service_name"`
	ServiceDesc       string `json:"service_desc" form:"service_desc" comment:"服务描述" validate:"required"`
	Port              int    `json:"port" form:"port" comment:"端口，需要设置8001-8999范围内" validate:"required,min=8001,max=8999"`
	HeaderTransfor    string `json:"header_transfor" form:"header_transfor" comment:"metadata转换" validate:"valid_header_transfor"`
	OpenAuth          int    `json:"open_auth" form:"open_auth" comment:"是否开启权限验证" validate:""`
	BlackList         string `json:"black_list" form:"black_list" comment:"黑名单IP，以逗号间隔，白名单优先级高于黑名单" validate:"valid_iplist"`
	WhiteList         string `json:"white_list" form:"white_list" comment:"白名单IP，以逗号间隔，白名单优先级高于黑名单" validate:"valid_iplist"`
	WhiteHostName     string `json:"white_host_name" form:"white_host_name" comment:"白名单主机，以逗号间隔" validate:"valid_iplist"`
	ClientIPFlowLimit int    `json:"clientip_flow_limit" form:"clientip_flow_limit" comment:"客户端IP限流" validate:""`
	ServiceFlowLimit  int    `json:"service_flow_limit" form:"service_flow_limit" comment:"服务端限流" validate:""`
	RoundType         int    `json:"round_type" form:"round_type" comment:"轮询策略" validate:""`
	IPList            string `json:"ip_list" form:"ip_list" comment:"IP列表" validate:"required,valid_ipportlist"`
	WeightList        string `json:"weight_list" form:"weight_list" comment:"权重列表" validate:"required,valid_weightlist"`
	ForbidList        string `json:"forbid_list" form:"forbid_list" comment:"禁用IP列表" validate:"valid_iplist"`
}

func (params *ServiceAddGrpcInput) BindValid(c *gin.Context) error {
	return public.DefaultGetValidParams(c, params)
}
func (params *ServiceUpdateGrpcInput) BindValid(c *gin.Context) error {
	return public.DefaultGetValidParams(c, params)
}

func (params *ServiceAddTCPInput) BindValid(c *gin.Context) error {
	return public.DefaultGetValidParams(c, params)
}
func (param *ServiceAddHTTPInput) BindValid(c *gin.Context) error {
	return public.DefaultGetValidParams(c, param)
}

func (param *ServiceListInput) BindValid(c *gin.Context) error {
	return public.DefaultGetValidParams(c, param)
}

func (param *ServiceDelInput) BindValid(c *gin.Context) error {
	return public.DefaultGetValidParams(c, param)
}

func (param *ServiceUpdateHTTPInput) BindValid(c *gin.Context) error {
	return public.DefaultGetValidParams(c, param)
}

func (param *ServiceUpdateTCPInput) BindValid(c *gin.Context) error {
	return public.DefaultGetValidParams(c, param)
}
